package com.lc.YYGH.user.controller.api;

import com.lc.YYGH.common.result.Result;
import com.lc.YYGH.common.utils.AuthContextHolder;
import com.lc.YYGH.model.user.Patient;
import com.lc.YYGH.user.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/user/patient")
@Api(tags="")
public class PatientApiController {
    @Autowired
    private PatientService patientService;
    @GetMapping("auth/findAll")
    public Result findAll(HttpServletRequest request)
    {
        Long userId= AuthContextHolder.getUserId(request);
        List<Patient> list=patientService.findAllByUserId(userId);
        return Result.success(list);
    }
    @PostMapping("auth/save")
    public Result savePatient(@RequestBody Patient patient, HttpServletRequest request)
    {
        Long userId=AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.success();
    }
    @GetMapping("auth/get/{id}")
    public Result getPatient(@PathVariable Long id)
    {
        Patient patient=patientService.getPatientById(id);
        return Result.success(patient);
    }
    @PutMapping("auth/update")
    public Result updatePatient(@RequestBody Patient patient)
    {
        patientService.updateById(patient);
        return Result.success();
    }
    @DeleteMapping("auth/remove/{id}")
    public Result removePatient(@PathVariable Long id)
    {
        patientService.removeById(id);
        return Result.success();


    }
    @ApiOperation(value="获取就诊人")
    @GetMapping("inner/get/{id}")
    public Patient getPatientById(
            @ApiParam(name="id",value="就诊人id",required=true)
            @PathVariable("id") Long id){
        return patientService.getPatientById(id);
    }

}
